//
//  ViewController.m
//  UISegmentControl
//
//  Created by clz on 2019/8/11.
//  Copyright © 2019年 clz. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //UISegmentControl
    
    NSArray *data = @[@"1",@"2",@"3"];
    
    UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:data];
    [segment addTarget:self action:@selector(click:) forControlEvents:UIControlEventValueChanged];
    [segment insertSegmentWithTitle:@"4" atIndex:3 animated:YES];
    [segment removeSegmentAtIndex:0 animated:YES];
    [segment setTintColor:[UIColor greenColor]];
    [segment setBackgroundColor:[UIColor redColor]];
    
    [self.view addSubview:segment];
    segment.frame = CGRectMake(20, 20, 200, 44);
    
    
}

- (void)click:(UISegmentedControl *)sender{
    NSLog(@"第%ld个",(long)sender.selectedSegmentIndex);
}




@end
